<?php

namespace common\components\db;

use Yii;
use yii\db\Connection as BaseConnection;


class Connection extends BaseConnection
{
    /**
     * @param null $sql
     * @param array $params
     * @return Command
     * @throws \yii\base\InvalidConfigException
     */
    public function createCommand($sql = null, $params = [])
    {
        $driver = $this->getDriverName();
        $config = ['class' => '\common\components\db\Command'];
        if (isset($this->commandMap[$driver])) {
            $config = !is_array($this->commandMap[$driver]) ? ['class' => $this->commandMap[$driver]] : $this->commandMap[$driver];
        }
        $config['db'] = $this;
        $config['sql'] = $sql;
        /** @var Command $command */
        $command = Yii::createObject($config);
        return $command->bindValues($params);
    }
}
